//#preprocess
/**
 * AUTO_COPYRIGHT_SUB_TAG
 */
package com.rim.samples.device.push.ui;

import net.rim.device.api.ui.component.*;

/**
 * Asks for user credentials before subscribing with Content Provider
 */
public class UserCredentialsDialog extends Dialog {

    private EditField _username;
    private PasswordEditField _password;

    public UserCredentialsDialog( String username ) {
        super( Dialog.D_OK_CANCEL, "Provide Your Credentials", Dialog.OK, null, Dialog.GLOBAL_STATUS );
        if( username == null ) {
            username = "";
        }
        _username = new EditField( "Username: ", username );
        _password = new PasswordEditField( "Password: ", "" );
        
        add( _username );
        add( _password );
    }

    public String getUsername() {
        return _username.getText();
    }

    public String getPassword() {
        return _password.getText();
    }

//#ifndef HANDHELD_VERSION_42
    protected void onUiEngineAttached( boolean attached ) {
        super.onUiEngineAttached( attached );
        if( attached ) {
            focusPasswordField();
        }
    }
//#endif
    
//#ifdef HANDHELD_VERSION_42
    protected void onDisplay() {
        super.onDisplay();
        focusPasswordField();
    }
//#endif

    private void focusPasswordField() {
        if( _username.getText().length() > 0 ) {
            _password.setFocus();
        }
    }
    
}
